{% extends "base_detail.html" %}

{% load i18n %}
{% load markup %}
{% load breadcrumbs %}
{% load menu %}

{% block breadcrumbs %}
    {% add_crumb 'Home' '/' %}
    {% add_crumb 'Polls' '/polls/' %}
    {% add_crumb object %}
{% endblock %}

{% block title %}
<div class="title">
    {% if object.closed %}<p class="meta">{% blocktrans with object.closed as closed %}Closed on {{ closed }}{% endblocktrans %}</p>{% endif %}
    <h1>{{ object|escape|capfirst }}</h1>
    <h2>{% block subtitle %}{% trans "Details" %}{% endblock %}</h2>
</div>
{% endblock %}

{% block objectactions %}
{% if perms.knowledge.add_poll %}
<li class="add"><a title="{% trans 'Add' %}" href="{% url poll_add %}">{% trans 'Add' %}</a></li>
{% endif %}
{% if object.pk in obj_perms.knowledge.change_poll %}
<li class="edit"><a title="{% trans 'Edit' %}" href="{% url poll_edit object.pk %}">{% trans 'Edit' %}</a></li>
{% endif %}
{% if object.pk in obj_perms.knowledge.delete_poll %}
<li class="delete"><a title="{% trans 'Delete' %}" href="{% url poll_delete object.pk %}">{% trans 'Delete' %}</a></li>
{% endif %}
{% if perms.knowledge.view_poll %}
<li class="all"><a title="{% trans 'All' %}" href="{% url poll_list %}">{% trans 'All' %}</a></li>
{% endif %}
{% if perms.knoweldge.view_poll %}
{% if user not in object.stream.followers.all %}
<li class="follow"><a title="{% trans 'Follow' %}" href="{% url stream_follow object.stream request.path %}">{% trans 'Follow' %}</a></li>
{% else %}
<li class="leave"><a title="{% trans 'Leave' %}" href="{% url stream_leave object.stream request.path %}">{% trans 'Leave' %}</a></li>
{% endif %}
{% endif %}
{% endblock %}

{% block objectmenu %}{% menu "poll_menu" %}{% endblock %}

{% block section %}
<div class="details">
    {% if object.description %}
    {{ object.description|markdown }}
    {% else %}
    <p class="disabled">{% trans "No description." %}</p>
    {% endif %}
    <ul class="choices">
        {% for choice in object.choices.all %}
        <li class="choice">
            {% if object.closed %}{{ choice }}{% else %}<a href="{{ choice.get_absolute_url }}">{{ choice }}</a>{% endif %}
            <span class="counter">{% widthratio choice.votes.count object.vote_count 100 %}% [{{ choice.votes.count }}]</span>
        </li>
        {% endfor %}
    </ul>
    <p class="vote-counter">{% blocktrans with vote_count=object.vote_count %}<strong>{{ vote_count }}</strong> vote(s){% endblocktrans %}</p>
    <p>
        {% include "elements/categories.html" %}
        {% include "elements/tags.html" %}
    </p>
</div>
{% include "elements/comments.html" %}
{% endblock %}
